// 获取boolean值
export function booleanFun(value, boolean = true) {
  if (value === undefined || value === null) {
    return boolean
  }
  const type = typeof (value)
  if (type === 'function') {
    return booleanFun(value())
  }
  if (type === 'boolean') {
    return value
  }
  console.error(`booleanFun函数不生效，最终解析结果应为boolean类型，当前解析结果为：${type} 类型`)
}

// 获取选项数据
export async function geItemsData(dict, value, binding) {
  if (dict) {
    this.$emit('update:keyName', 'dictValue')
    this.$emit('update:labelName', 'dictLabel')
    return (await this.getDicts(dict)).data
  }
  const type = typeof (value)
  if (type === 'function') {
    const itemData = await value()
    if (binding) {
      return binding.split('.').reduce((total, cur) => total[cur], itemData)
    } else {
      return itemData
    }
  }
  return value
}

// 判断不为空
export function notNull(value) {
  return value !== undefined && value != null && value !== ''
}

// sync data改变值
export const currentData = {
  get() {
    return this.data
  },
  set(value) {
    this.$emit('update:data', value)
  }
}
